package com.back.service.impl;

import com.back.entity.Log;
import com.back.mapper.LogDao;
import com.back.service.inte.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    LogDao logDao;
    @Value("${cache_time}")
    int cache_time;

    @Override
    public void add(Log log) {
        logDao.add(log);
    }

    @Override
    public List<Log> query(int current, int pagesize) {
        return logDao.query((current - 1) * pagesize, pagesize);
    }

    @Override
    public int totalnum() {
        return logDao.totalnum();
    }

    @Override
    public int getuid(String username, String url, String ip, String msg) {
        Integer id = logDao.queryId(username, url, cache_time);
        if (id == null) {
            Log log = Log.ok(url, username, ip, msg);
            logDao.add(log);
            return log.getId();
        } else {
            return id;
        }
    }
}
